﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class FinishMasterData : BaseFunction
    {


        public FinishMasterData()
            : base()
        {

        }
        public FinishMasterData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DataSet GetFinishMaster(DataRow dwWAFARBEN)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT*FROM INTEX.WASTAMM WHERE WAART =:ArticleNum AND WAVAR=:ArticleVar";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                or1.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(or1);

                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTAMM";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetFinishColorWay(DataRow dwWAFARBEN)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT WAFART, WAFVAR,WAFZUART,WAFZUSATZ,WAFBEZ" +
                    " FROM INTEX.WAFARBEN WHERE WAFART = :ArticleNum AND WAFVAR=:ArticleVar "
                 + " AND WAFZUSATZ=:ArticleColor";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                or1.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                or1.Parameters.Add("ArticleColor", OracleType.NVarChar).Value = dwWAFARBEN["WAFZUSATZ"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WAFINISH";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet LoadWAASTAMM(string UsingID, string article = "")
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            try
            {
                UsingID = UsingID.Trim();
                UsingID = UsingID.Replace("\t", "");
                UsingID = Left(UsingID + "        ", 8);
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT Distinct WAART as  ArtNum, WAVAR as ArtVar,WABEZ as ArtDes"
               + " FROM INTEX.WASTAMM WHERE  WAKUNDNR='00000000' AND WAART like '%" + article + "%' AND warfertkz = 'E' AND WAFFERTKZ = 'E' "
                + " AND (WANEUB = '" + UsingID + "' OR '" + UsingID + "' IN ('FPDE    ','XHJUN   ')) order by 1 desc";

                setResult = Connect2Proxy(or1);

                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ARTICLE";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet BuildFinishMasterData(DataRow dwWAFARBEN)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                setResult = GetFinishColorWay(dwWAFARBEN);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}